// Stack.cpp: implementation of the CStack class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Stack.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CStack::CStack()
{
	data=(stackh*)malloc(sizeof(stackh));
	data->length=0;
	data->ptostack=NULL;
}

CStack::~CStack()
{
}

int CStack::Pop()
{
	if(!data->ptostack)
	{
		CString fmt;
		fmt = "No Data in Stack";
		::AfxMessageBox(fmt);
		return FALSE;
	}
	stackdt *p=data->ptostack;
	int i;
	i=p->sdata;
	data->ptostack=p->ptonext;
	data->length--;
	free(p);
	return i;
}

int CStack::GetLength()
{
	return data->length;
}


void CStack::Push(int i)
{
	stackdt *q;
	stackdt *p=(stackdt*)malloc(sizeof(stackdt));
	q=data->ptostack;
	p->ptonext=q;
	p->sdata=i;
	data->ptostack=p;
	data->length++;
	return;
}

BOOL CStack::isEmpty()
{
	if(data->length==0)
		return TRUE;
	else return FALSE;
}
